﻿# Vanilla override
# character having its birthday in root scope
# tested after age has increased
on_birthday = {
	on_actions = {
		on_specific_birthday
		on_birthday_childhood
		on_birthday_adulthood
		on_graceful_aging_birthday
	}
}

on_specific_birthday = {
	first_valid_on_action = {
		on_3rd_birthday
		on_6th_birthday
		on_7th_birthday_ua
		on_10th_birthday_ua
		on_12th_14th_birthday_ua # adulthood
	}
}

# THIS BLOCK FIXES THE TRAIT PROBLEM
on_12th_14th_birthday_ua = {
    trigger = {
        OR = {
            AND = { is_female = yes age = 12 }
            AND = { is_male = yes age = 14 }
        }
    }
    immediate = {
        education_trait_based_on_focus = yes  # ← ADDS EDUCATION TRAIT
        child_personality_gain_ua = yes
    }
    on_actions = {
        on_birthday_adulthood
    }
}

on_birthday_childhood = {
	trigger = {
		OR = {
			is_adult = no
			is_ua_adult_preadult = yes
		}
		age >= childhood_education_start_age
	}
	on_actions = {
		child_personality_gain_ua
		childhood_education_ua
		on_action_add_sexuality
		reincarnation_toy_pulse
	}
	effect = {
		if = {
			limit = {
				any_parent = {
					is_playable_character = yes
					highest_held_title_tier >= tier_duchy
					any_memory = {
						memory_type = ascended_throne_memory
						has_variable = childhood_memory
						save_temporary_scope_as = throne_memory_temp
					}
				}
			}
			random_parent = {
				limit = {
					is_playable_character = yes
					highest_held_title_tier >= tier_duchy
					any_memory = {
						memory_type = ascended_throne_memory
						has_variable = childhood_memory
						save_temporary_scope_as = throne_memory_temp
					}
				}
				trigger_event = bp2_yearly.4003 #This event has further triggers, as well as a cooldown, and may still fail.
			}
		}

		if = {
			limit = {
				culture = {
					has_cultural_parameter = strong_traits_more_common
				}
				NOR = {
					has_trait = strong
					has_trait = weak
					has_trait = physique_bad
				}
			}
			random = {
				chance = {
					value = 0
					if = {
						limit = { age >= 30 }
						add = 100
					}
				}
				add_trait = strong
			}
		}

		random = {
			chance = { value = 30 }
			tgp_learn_chinese_effect_birthday = yes
		}
	}
	random_events = {
		900 = 0
		150 = childhood.2100 # Learn the Language of your parent
		150 = childhood.2200
		150 = childhood.2300 # Learn the Language of your parent
	}
}

reincarnation_toy_pulse = {
	random_events = {
		chance_to_happen = 14
		100 = bp2_yearly.8090 # Take the toy test to become a reincarnation (14 in 1,464 is roughly 1% in 100. This event can fire between the ages of 4 and 15, meaning there are 12 chances of this happening)
	}
}

on_birthday_adulthood = {
	trigger = {
		is_adult = yes
	}
	random_events = {
		chance_to_happen = 25
		1000 = 0
		1 = bp1_yearly.3004 # Surprise Birthday Party
		30 = bp1_yearly.3006 # Reflecting on the surprise party years later
	}
	effect = {
		if = {
			limit = {
				culture = { has_cultural_parameter = peasant_leader_is_inherited }
				any_parent ?= {
					even_if_dead = yes
					culture = root.culture
					has_trait = peasant_leader
				}
			}
			add_trait = peasant_leader
		}
	}
}

on_graceful_aging_birthday = {
	trigger = {
		dynasty ?= { has_dynasty_perk = kin_legacy_5 }
		age >= kin_legacy_5_start_age # Start at 40 - This trigger is here to prevent the calculation running for everyone
		save_temporary_scope_value_as = {
			name = age_check
			value = kin_legacy_5_age_modulo
		}
		scope:age_check = 0
	}
	events = {
		dynasty_legacy.0001 # Gain a random skill point
	}
}